import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:ty_smart_watch/bean/health_detail_bean.dart';
import 'package:ty_smart_watch/page/health/controller/common_controller.dart';

class DataView extends StatelessWidget {
  const DataView({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    final CommonController _controller = Get.find();

    var count = 10;
    return Container(
      margin: const EdgeInsets.all(10),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        boxShadow: const [
          BoxShadow(color: Colors.grey, offset: Offset(0, 0), blurRadius: 8, spreadRadius: 0),
        ],
        //圆角半径
        borderRadius: const BorderRadius.all(Radius.circular(12.0)),
        //边框线宽、颜色
        border: Border.all(width: 1.0, color: const Color(0xFFFAFAFA)),
        // 背景色
        color: const Color(0xFFFAFAFA),
      ),

      child: Obx(
        () => ListView.builder(
          itemCount: _controller.detailList.value.length,
          itemBuilder: (context, index) {
            if (index == 0) {
              return DataTitle(title: title);
            } else {
              return DataItem(bean: _controller.detailList.value[index - 1]);
            }
          },
        ),
      ),

      // child: ListView.builder(
      //   itemCount: count,
      //   itemBuilder: (context, index) {
      //     if (index == 0) {
      //       return DataTitle(title: title);
      //     } else {
      //       return DataItem();
      //     }
      //   },
      // ),
    );
  }
}

class DataTitle extends StatelessWidget {
  const DataTitle({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    var _styel = const TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.black);
    return Row(
      children: [
        Expanded(child: Text("日期", textAlign: TextAlign.center, style: _styel)),
        Expanded(
            child: Text(
          "时间",
          textAlign: TextAlign.center,
          style: _styel,
        )),
        Expanded(
            child: Text(
          title,
          textAlign: TextAlign.center,
          style: _styel,
        )),
      ],
    );
  }
}

class DataItem extends StatelessWidget {
  const DataItem({super.key, required this.bean});

  final HealthDetailBean bean;

  @override
  Widget build(BuildContext context) {
    var _styel = const TextStyle(fontSize: 13, color: Color(0xFF898996));
    var now = DateTime.now();
    String date = DateFormat('yyyy-MM-dd').format(now);
    String time = DateFormat('HH:mm:ss').format(now);
    return Column(
      children: [
        const SizedBox(height: 6),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(child: Text(date, textAlign: TextAlign.center, style: _styel)),
            Expanded(child: Text(time, textAlign: TextAlign.center, style: _styel)),
            Expanded(child: Text(bean.data, textAlign: TextAlign.center, style: _styel)),
          ],
        ),
        const SizedBox(height: 6),
        Container(
          height: 0.5,
          color: const Color(0xFFDCDCDC),
        )
      ],
    );
  }
}
